import java.util.Stack;


public class RuleLambdaClosure {

	/*
	 * lambda:3:x:env#
	 */
	
	Stack<ControlElement> control ;
	Stack<String> stack ;
	Environment environment;
	
	public RuleLambdaClosure(Stack<ControlElement> control, Stack<String> stack, Environment environment){
		this.control = control;
		this.stack = stack;
		this.environment = environment;
	}
	
	public static void main(String[] args) {
		Stack<ControlElement> control = new Stack<ControlElement>();
		Stack<String> stack = new Stack<String>();
		Environment environment = new Environment();
		environment.currentEnv = environment.addEnv(0);
		environment.currentEnv = environment.addEnv(0);
		RuleLambdaClosure ruleLambda = new RuleLambdaClosure(control, stack, environment);

		// test1 
		control.push(new ControlElement("lambda:2:y"));
		System.out.println(ruleLambda.checkRule());
		//ruleOP.devide();
		//ruleOP.power();
		ruleLambda.applyRule();
		System.out.println("Control:"+ruleLambda.control + " Stack:" +ruleLambda.stack);
	}
	
	/*
	 * control = lambda object
	 * stack = lambda:3:x:envNo
	 * or
	 * lambda:delta#:x:y:z:envNo
	 * either case we append the env at the back
	 */
	public void applyRule() {
		ControlLambda ctrlLambda = (ControlLambda)control.pop();
		String lambda = ctrlLambda.toString(); 
		lambda = lambda + ":" + environment.currentEnv;
		stack.push(lambda);
	}

	public boolean checkRule() {
		if (control.peek() instanceof ControlLambda)
			return true;
		else
			return false;
	}
}
